class Dep {
  constructor() {
    this.subscribers = new Set(); // 存放收集的依赖，即副作用函数
  }

  addEffect(effect) {
    this.subscribers.add(effect);
  }

  notify() {
    this.subscribers.forEach((effect) => effect());
  }
}

const info = { counter: 100 };
const dep = new Dep();

function doubleCounter() {
  console.log(info.counter * 2);
}

function powerCounter() {
  console.log(info.counter * info.counter);
}
// 手动收集依赖
dep.addEffect(doubleCounter);
dep.addEffect(powerCounter);

info.counter++;
dep.notify();
